home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 23 / Amiga Format AFCD23 (Feb 1998, Issue 107).iso / -screenplay- / shareware / progammon2.21 / dicetests / dice.docs < prev    next >
Text File  |  1997-12-01  |  4KB  |  76 lines

  1. Testing the Dice:
  2.  
  3. Have you ever noticed while playing ProGammon that sometimes the computer
  4. rolls exactly what it needs?  Have you ever thought that the dice are not
  5. truly random or that the program is just plain cheating!  To be honest,
  6. I was curious as to whether the dice are random so I wrote a small program
  7. to test them.  The dice tests convinced me so now let's see if I can
  8. convince you.
  9.  
  10. First off, the program uses the UNIX compatible SAS/C random number
  11. generating function called drand48().  It also uses the function
  12. srand48( seed ) to set the random number seed.  drand48() produces random
  13. numbers between the values of 0.0 and 1.0 but not including 1.0.  The 
  14. following is how I convert this value into a dice value:
  15.  
  16.     dice[ 1 ] = (int)( ceil( drand48() * 6.0 ) );
  17.     dice[ 2 ] = (int)( ceil( drand48() * 6.0 ) );
  18.     
  19. These 2 simple lines of C code are what controls the dice.  The RollDice()
  20. subroutine has no idea whether it is being called to roll the dice for you
  21. or for the Amiga.  It does not check to see who is on the bar or what
  22. points are blocked or whether it's the start of the game or the end.  All
  23. it does is just roll the dice.  The Amiga is not cheating just because it
  24. rolls a 6 to start the game or rolls doubles to end the game.  It has
  25. gotten lucky and if you play enough games I'm sure that you will get lucky
  26. too.  If you don't think the dice are random then I guess you should send
  27. your complaints to the people who wrote the drand48() function.  Before
  28. you do though, I think you should try running the following DiceTest 
  29. program.  This proved to me that the drand48() function produces random
  30. numbers that are just as random as any set of dice.
  31.  
  32.  
  33.  
  34. DiceTest:
  35.  
  36. This program rolls a set of dice 108 000 times to see if every combination
  37. is equally likely.  You should see each combination 1/36th of the time so
  38. you can expect to see about 3 000 entries for each.  This program will
  39. produce a 6 x 6 table to show you the results.
  40.  
  41. Have you ever noticed the exact same thing being rolled twice in a row.
  42. Also, sometimes you will roll a 5 2 and then a 2 5.  With normal dice,
  43. either one of these events will occur 1/36th of the time.  This test
  44. checks for these 2 events which should occur about 3 000 times.
  45.  
  46. The next test checks for the same thing being rolled 3 times in a row.
  47. If the Amiga rolled double sixes 3 times in a row you would probably be
  48. a little suspicious but this does occur with normal dice 1/1296 of the
  49. time.  In this test we should see this happen about 83 times.  
  50.  
  51. Checking for the frequency of doubles is the next test.  A normal pair of
  52. dice will come up with doubles approximately 1/6th of the time.  After
  53. 108 000 rolls you would expect there to be about 18 000 doubles.
  54.  
  55. Finally, the total amount rolled is computed.  Each roll in backgammon
  56. averages 8.167 when taking doubles into account so the total should be
  57. somewhere around 882 000 if these dice are legal.
  58.  
  59. This test was written in C and is about 130 lines long.  If you would
  60. like to examine this testing program further then just let me know and I
  61. will be happy to send it to you.
  62.  
  63. I hope that running these tests will convince you that the dice used in
  64. ProGammon are 100% random.  Of course, there are going to be some people
  65. who are willing to agree that these dice are random but the ones in the
  66. game are not.  For this reason, ProGammon 2.2 also compiles statistics
  67. while you play.  Your average dice roll should start to approach the
  68. theoretical value of 8.167 within about 25 games.  Hopefully, this will
  69. help prove to you that the Amiga does not cheat and is merely playing a
  70. damn good game of backgammon!  Go ahead, see for yourself.
  71.  
  72. During the game you can select  Stats  in the menus to see the averages
  73. for the games that you are presently playing.  The program  PrintStats
  74. will display the statistics that are saved in the  gammon.prefs  file.
  75. This program and file should be placed in the same directory.
  76.